

/**
 * DataTables
 */
var datatable = null,idList=[];

$(function() {
	getIssuePeriodSelectList();
	datatable = $('.table-sort').dataTable({
		order: [
			[1, 'asc']
		],
		bRetrieve: true,
		autoWidth: true,
		searching : false,
		lengthChange: false,	
		processing: true, //当datatable获取数据时候是否显示正在处理提示信息。
		serverSide: true, //服务器处理分页
		responsive: {
			details: false
		},
	    //lengthMenu: [10],   // 每页显示数据（默认是10）
	    ordering: false,//是否允许用户排序
	    paging: true,//是否分页
	    pagingType: "full_numbers",//除首页、上一页、下一页、末页四个按钮还有页数按钮
	    /* scrollX: true,//允许水平滚动
	     scrollY: "200px",
	     scrollCollapse: true, */
	    stateSave: false,//刷新时是否保存状态
	    //deferRender: true,//延迟渲染
		ajax: {
			url: contextPath + "/commission/getPageList",
			type: 'post',
			data: function(d) {
				d.issuePeriodId = $('#issuePeriodSelectList').val();
				d.fullName = $('#fullName').val();
			}
		},	
		language: {
			"url": "../resources/js/datatables_language.json"
		},
		columns: [
			{data: "inventoryId"},
			{data: "cardNumber",defaultContent: ""},
			{data: "verifyCode",defaultContent: ""},
			{data: "fullName",defaultContent: ""},
			{data: "phone",defaultContent: ""},
			{data: "commissionType",defaultContent: ""},
			{data: "commission",defaultContent: ""},
			{data: "state",defaultContent: ""},
			{data: "cardType",defaultContent: ""},
			{data: "issuePeriodAlias"},
			{data: null}
			],
		columnDefs: [{
			targets: [0],
			orderable:false,
			render: function(data, type, row, meta) {
				return '<input id="input-' + data + '" type="checkbox" name="single"><label for="input-' + data + '"></label>';
			}  
		},{
			targets: [5],
			render: function(data, type, row, meta) {
				if (data == 1) return '数量提成';
				else if (data == 2) return '比例提成';
			}
		}, {
			targets: [7],
			render: function(data, type, row, meta) {
				if (data == 0 || data == 2) return '已发行';
				else if (data == 1) return '已绑定';
				else if (data == 3) return '已领取';
				else if (data == 4) return '已退货';
				else if (data == 5) return '已过期';
			}
		},{
			targets: [10],
			orderable:false,
			responsivePriority: 1,
			render: function(data, type, row, meta) {
				var btns = new Array('edit','del');
				return getDTOperateBtn(btns, row.inventoryId, '/commission/commission-add.html', null, '/commission/delete', reloadTable);
			}
		}]
	});

});
function getIssuePeriodSelectList(){
	jQuery.ajax({
		type:"POST",
		dataType:"json",
		url:contextPath + "/issuePeriod/getSelectList",
		success:function(data){
			var unitObj=document.getElementById("issuePeriodSelectList");
			if(data != null){
				//alert(JSON.stringify(selectList));
				for(var i = 0; i < data.length; i++){
					//先创建好select里面的option元素
					var option = document.createElement("option");
					//转换DOM对象为JQ对象,好用JQ里面提供的方法 给option的value赋值
					$(option).val(data[i].value);
					//给option的text赋值,这就是你点开下拉框能够看到的东西
					$(option).text(data[i].text);
					//获取select 下拉框对象,并将option添加进select
					$('#issuePeriodSelectList').append(option);
				
				}
			}
		},
		error:function(){
			J.alert('Error loading Json document');
		}
	});
}
function selectOnchange(){
	$('.table-sort').dataTable().fnDraw(false);
}
